package com.wedo.mall.activity.comment;

import android.os.Bundle;

import com.e.library.activity.EActivity;
import com.e.library.http.EApi;
import com.e.library.utils.EViewUtils;
import com.e.library.widget.ETitleBar;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.wedo.mall.R;
import com.wedo.mall.adapter.CommentAdapter;
import com.wedo.mall.entity.Comment;
import com.wedo.mall.ptr.Pull2Refresh;

import butterknife.BindView;

/**
 * 商品详情
 * Created by e on 2017/7/11.
 */

public class CommentActivity extends EActivity {

    public static final int TYPE_AGENT = 0;
    public static final int TYPE_GOODS = 1;
    public static final String EXTRA_ID = "id";
    public static final String EXTRA_TYPE = "type";

    @BindView(R.id.title_bar) ETitleBar title_bar;
    @BindView(R.id.rv_comment) XRecyclerView rv_comment;

    public static void toComment(EActivity activity,String goods_id){
        toComment(activity,TYPE_GOODS,goods_id);
    }

    public static void toAgentComment(EActivity activity,String id){
        toComment(activity,TYPE_AGENT,id);
    }

    public static void toComment(EActivity activity,int type,String id){
        Bundle bundle = new Bundle();
        bundle.putInt(EXTRA_TYPE,type);
        bundle.putString(EXTRA_ID,id);
        activity.toActivity(CommentActivity.class,bundle);
    }

    @Override
    protected int layout() {
        return R.layout.activity_comment;
    }

    @Override
    protected void onActivityCreated(Bundle state) {

        String id = getIntent().getStringExtra(EXTRA_ID);
        int type = getIntent().getIntExtra(EXTRA_TYPE,TYPE_GOODS);

        String url = EApi.COMMENT_GOODS;
        String key = "goods_id";
        title_bar.setTitle(R.string.goods_purchase_review);
        if (type == TYPE_AGENT){
            url = EApi.AGENT_COMMENT;
            key = "id";
            title_bar.setTitle(R.string.agent_review_list);
        }

        rv_comment.setHasFixedSize(true);
        EViewUtils.vertical(rv_comment);

        Pull2Refresh<Comment> ptr = new Pull2Refresh<>();
        ptr.widget(rv_comment).adapter(new CommentAdapter(this,null)).url(url).param(key,id).clazz(Comment.class).done();
    }
}
